import {
	deleteCatalog
} from '@/api/data/tbNetDefCatalog';
export default {
	props: {
		value: {
			type: Array,
			default: () => []
		},
		list: {
			type: Array,
			default: () => []
		}
	},
	data() {
		return {
			checkecData: this.value,
		}
	},
	watch: {
		value(arr) {
			this.checkecData = arr;
		},
		checkecData(arr) {
			this.$emit('input', arr);
		}
	},
	methods: {
		handleDataOperate(type, data) {
			this.$emit('hand', type, data);
		},

		//删除数据
		handleDeleteData(data) {
			let that = this;
			that.$confirm(`此操作将永久删除编目定义<font color="#f00">【${data.name}】</font>, 是否继续?`, '提示', {
				type: 'warning',
				dangerouslyUseHTMLString: true,
				async beforeClose(action, instance, done) {
					if (action === 'confirm') {
						instance.confirmButtonLoading = true;
						await that.deleteDataRequest(data.id);
						instance.confirmButtonLoading = false;
						done();
					} else {
						done();
					}
				}
			}).catch(() => {});
		},

		//删除编目定义请求
		async deleteDataRequest(id) {
			let result = await deleteCatalog(id).then((res) => res.data);
			if (result.code === '0') {
				this.$message.success('删除编目定义成功');
				this.$emit('hand', 'refresh');
			} else {
				this.$message.error('删除编目定义失败');
			}
		}
	}
}